﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.Record;
using TyMES.Model;

namespace TyMES.ViewModel.Record.ProduceDataRecordVMs
{
    public partial class ProduceDataRecordListVM : BasePagedListVM<ProduceDataRecord_View, ProduceDataRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProduceDataRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<ProduceDataRecord_View>>{
                
                this.MakeGridHeader(x => x.ProduceDataRecord_SN).SetTitle(@Localizer["Page.SN号"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_StationCode).SetTitle(@Localizer["Page.工位编号"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_DataName).SetTitle(@Localizer["Page.数据名称"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_Result).SetTitle(@Localizer["Page.结果"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_Data).SetTitle(@Localizer["Page.数据"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_SqlTime).SetTitle(@Localizer["Page.上传服务器时间"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_SqlFlag).SetTitle(@Localizer["Page.上传标识"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_Actualsort).SetTitle(@Localizer["Page.实际顺序"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProduceDataRecord_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProduceDataRecord_View> GetSearchQuery()
        {
            var query = DC.Set<ProduceDataRecord>()
                
                .CheckContain(Searcher.SN, x=>x.SN)
                .CheckContain(Searcher.StationCode, x=>x.StationCode)
                .CheckContain(Searcher.DataName, x=>x.DataName)
                .CheckContain(Searcher.Result, x=>x.Result)
                .CheckContain(Searcher.Data, x=>x.Data)
                .CheckContain(Searcher.SqlTime, x=>x.SqlTime)
                .CheckEqual(Searcher.SqlFlag, x=>x.SqlFlag)
                .CheckEqual(Searcher.Actualsort, x=>x.Actualsort)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProduceDataRecord_View
                {
				    ID = x.ID,
                    
                    ProduceDataRecord_SN = x.SN,
                    ProduceDataRecord_StationCode = x.StationCode,
                    ProduceDataRecord_DataName = x.DataName,
                    ProduceDataRecord_Result = x.Result,
                    ProduceDataRecord_Data = x.Data,
                    ProduceDataRecord_SqlTime = x.SqlTime,
                    ProduceDataRecord_SqlFlag = x.SqlFlag,
                    ProduceDataRecord_Actualsort = x.Actualsort,
                    ProduceDataRecord_CreateTime = x.CreateTime,
                    ProduceDataRecord_UpdateTime = x.UpdateTime,
                    ProduceDataRecord_CreateBy = x.CreateBy,
                    ProduceDataRecord_UpdateBy = x.UpdateBy,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

        
    }
    public class ProduceDataRecord_View: ProduceDataRecord
    {
        
        public string ProduceDataRecord_SN { get; set; }
        public string ProduceDataRecord_StationCode { get; set; }
        public string ProduceDataRecord_DataName { get; set; }
        public string ProduceDataRecord_Result { get; set; }
        public string ProduceDataRecord_Data { get; set; }
        public string ProduceDataRecord_SqlTime { get; set; }
        public bool? ProduceDataRecord_SqlFlag { get; set; }
        public int? ProduceDataRecord_Actualsort { get; set; }
        public DateTime? ProduceDataRecord_CreateTime { get; set; }
        public DateTime? ProduceDataRecord_UpdateTime { get; set; }
        public string ProduceDataRecord_CreateBy { get; set; }
        public string ProduceDataRecord_UpdateBy { get; set; }

    }

}